package com.ruoyi.web.controller.house;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.data.DataUtils;
import com.ruoyi.parameter.domain.HouseDoorParameterT;
import com.ruoyi.parameter.service.IHouseDoorParameterTService;
import com.ruoyi.purpose.domain.HousePurposeT;
import com.ruoyi.purpose.service.IHousePurposeTService;
import com.ruoyi.setup.domain.HouseSetupT;
import com.ruoyi.setup.service.IHouseSetupTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 户参数修改Controller
 * 
 * @author tyq
 * @date 2023-04-25
 */
@RestController
@RequestMapping("/house/parameter")
public class HouseDoorParameterTController extends BaseController
{
    @Autowired
    private IHouseDoorParameterTService houseDoorParameterTService;
    @Autowired
    private IHousePurposeTService housePurposeTService;
    @Autowired
    private IHouseSetupTService houseSetupTService;

    /**
     * 查询户参数修改列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseDoorParameterT houseDoorParameterT)
    {
        startPage();
        List<HouseDoorParameterT> list = houseDoorParameterTService.selectHouseDoorParameterTList(houseDoorParameterT);
        return getDataTable(list);
    }

    /**
     * 获取户参数修改详细信息
     */
    @GetMapping(value = "/{doorId}")
    public AjaxResult getInfo(@PathVariable("doorId") Long doorId)
    {
        return AjaxResult.success(houseDoorParameterTService.selectHouseDoorParameterTByDoorId(doorId));
    }

    /**
     * 修改户参数修改
     */
     @Log(title = "户参数修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseDoorParameterT houseDoorParameterT) {

             HousePurposeT housePurposeT = new HousePurposeT();
             housePurposeT = housePurposeTService.selectHousePurposeTByPurposeId(houseDoorParameterT.getPurposeId());
             String FeeStandards = getFeeStandards();
             houseDoorParameterT.setCreater(getUsername());
         if (houseDoorParameterT.getPrice() != 0) {
             if ("1".equals(FeeStandards)) {
                 Double budgetMoney = DataUtils.multiplyTwo(houseDoorParameterT.getPrice(), houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             } else if ("2".equals(FeeStandards)) {
                 Double budgetMoney = DataUtils.saveTwoTruncation(houseDoorParameterT.getPrice() * houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             } else if ("4".equals(FeeStandards)) {
                 Double budgetMoney = DataUtils.saveOneTruncation(houseDoorParameterT.getPrice() * houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             } else if ("3".equals(FeeStandards)) {
                 Double budgetMoney = DataUtils.multiplyOne(houseDoorParameterT.getPrice(), houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             } else if ("5".equals(FeeStandards)) {
                 Double budgetMoney = DataUtils.doubleFloor(houseDoorParameterT.getPrice() * houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             } else {
                 Double budgetMoney = DataUtils.intFloor(houseDoorParameterT.getPrice() * houseDoorParameterT.getSpace());
                 houseDoorParameterT.setBudgetMoney(budgetMoney);
             }
         }
             return toAjax(houseDoorParameterTService.updateHouseDoorParameterT(houseDoorParameterT));

     }


    public String getFeeStandards(){
        HouseSetupT list = houseSetupTService.selectHouseSetupTByFeeStandards();
        return list.getFeeStandards();
    }
}
